package com.hound.controller;

import com.hound.model.TUser;
import com.hound.model.User;
import com.hound.service.UserService;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Created by lupeng on 2018/3/21.
 */
@Controller
public class TestController {

    @Autowired
    private UserService userService;

//    @Autowired
//    private HelloSender helloSender;

//    @RequestMapping("/testJsp")
//    public String testJsp(HttpServletRequest request){
//        request.setAttribute("name", "lupeng");
//        System.out.println("11111");
//        return "index";
//    }

    @Value("${editUrl}")
    private String port;

    @ResponseBody
    @RequestMapping("/test")
    public String test(HttpServletRequest request){
        return port;
    }

    @ResponseBody
    @RequestMapping("/test1")
    public String test1(HttpServletRequest request){
        TUser tUser = new TUser();
        tUser.setName("asdfsadfsf");
        return userService.addTUser(tUser).toString();
    }

//    @ResponseBody
//    @RequestMapping("/testMq")
//    public String testMq(HttpServletRequest request){
//        helloSender.send();
//        return "1";
//    }

    @RequestMapping("/html")
    public String html(HttpServletRequest request, Model model){
        model.addAttribute("name", "lupeng");
        return "select";
    }

    @RequestMapping("/html1")
    public String html1(HttpServletRequest request){
        return "select1";
    }

    @RequestMapping("/bs1")
    public String bs1(HttpServletRequest request){
        return "bootstrap-1";
    }

    @ResponseBody
    @RequestMapping("/data")
    public List<Map<String, String>> data(HttpServletRequest request){
        String sSearch = request.getParameter("sSearch");
        System.out.println(sSearch);
        List<Map<String, String>> maps = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("id", "1");
        map.put("text", "zhangsan");
        maps.add(map);

        Map<String, String> map1 = new HashMap<>();
        map1.put("id", "2");
        map1.put("text", "lisi");
        maps.add(map1);

        Map<String, String> map2 = new HashMap<>();
        map2.put("id", "3");
        map2.put("text", "wangwu");
        maps.add(map2);
        return maps;
    }
}